import 'dart:io';

void main(List<String> args) async {
  try{
    print("开始登陆");
   await login();
   print("结束登录");
  }catch(error){
    print(error);
  }
  

}

Future<String> login() async {
    LoginUser user=LoginUser("admin", "12346");
    if(user.checkIsEmpty()){
      print("用户名密码不能为空");
      return "fail";
    }
    String result=await longUserAPI(user);
    print(result);
    return "ok";
   
   }


Future<String> longUserAPI(LoginUser loginUser){

  return Future<String>((){
   sleep(Duration(seconds:1));
   if(loginUser.password != "123456"){
    throw Exception("密码错误");
   }
   return  "cdsssddfdaf";
  });
}

class LoginUser{
  String? uesrname;
  String? password;
  LoginUser(this.uesrname,this.password);
  bool checkIsEmpty(){
    return this.uesrname!.isEmpty || this.password!.isEmpty;
  }



}